import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// import loginPage from '../views/login'

const routes = [
    {path:'/',redirect:'/index'},
    { 
      path: '/index', 
      component:() => import('../views/index'),
      redirect:'/index/banners',
      meta:{title:'首页'},
      children:[
        {
          path:'banners',
          meta:{title:'轮播图管理'},
          component:() => import('../views/shouye/banner'),
          beforeEach:(to,from,next) => {
            ///reject the Navigation
            console.log('独享守卫')
            next()
          }
      },
        {path:'category',component:() => import('../views/shouye/category')},
        {path:'recomend',component:() => import('../views/shouye/recomend')},
    ]
    },
    { path: '/login', component:() => import('../views/login') }
  ]

const router = new VueRouter({
  routes, // `router: router`的缩写
})

///全局前置守卫
router.beforeEach((to,from,next) => {
  ///...
  ///返回false以取消导航
  // console.log(to,from)
  next()
  // return true
})

export default router